
<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <div class="seach-box">
        <div class="select-box-content">
          <div class="select-box-content-name">点检任务名称：</div>
          <el-input
            v-model="taskName"
            clearable
            placeholder="请输入点检任务名称"
            @change="queryPageList()"
          />
        </div>
        <div class="select-box-content">
          <div class="select-box-content-name">点检设备：</div>
          <el-input
            v-model="equipmentName"
            clearable
            placeholder="请输入点检设备"
            @change="queryPageList()"
          />
        </div>
        <div v-if="topitemtypeId==='任务'" class="select-box-content">
          <div class="select-box-content-name">选择时间：</div>
          <el-date-picker
            v-model="generationTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy/MM/dd"
            format="yyyy/MM/dd"
            clearable
            @change="queryPageList()"
          />
        </div>
        <div v-if="topitemtypeId==='异常任务'" class="select-box-content">
          <div class="select-box-content-name">选择时间：</div>开始时间
          <el-date-picker
            v-model="startTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy/MM/dd"
            format="yyyy/MM/dd"
            clearable
            @change="queryPageList()"
          />结束时间
          <el-date-picker
            v-model="endTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy/MM/dd"
            format="yyyy/MM/dd"
            clearable
            @change="queryPageList()"
          />
        </div>
        <!-- <div class="select-box-content">
          <div class="select-btns table-btns" @click.stop="changeSelect()">
            <i class="el-icon-circle-check"></i>
            <p v-if="activeName==='1'">收起筛选</p>
            <p v-if="activeName===''">展开筛选</p>
          </div>
        </div>-->
      </div>
      <!-- <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
          </template>
        </el-collapse-item>
      </el-collapse>-->
    </template>
    <template v-slot:typenodeslot>
      <SelectButton
        :topitem-select-list="topitemSelectList"
        @topitemtype="topitemtype"
      />
    </template>
    <template v-slot:content>
      <e-table
        ref="tableData"
        rowKey="taskCode"
        :table-data="tableData"
        :table-columns="tableLabel"
        :page="currentPage"
        :size="pageSize"
        :total="totalSize"
        :loading="loading"
        :table-option="tableOption"
        :showSelectColumn="false"
        :table-column-sum="topitemtypeId"
        @sizeChange="changePageSize"
        @pageChange="changeCurrentPage"
        @tableUpdatePlus="mixTableUpdatePlus"
      >
        <template
          v-if="scoped.row.taskCode"
          slot-scope="scoped"
          slot
          name="checkResult"
        >
          <div
            v-if="scoped.row['lowerLimit']||scoped.row['upperLimit']"
          >{{ scoped.row.lowerLimit?'下限:'+scoped.row.lowerLimit+scoped.row.unitName:'' }}{{ scoped.row.upperLimit?'上限:'+scoped.row.upperLimit+scoped.row.unitName:'' }}</div>
          <div v-else>{{ scoped.row.standardValue||'--' }}</div>
        </template>

        <template slot-scope="scoped" slot name="standardValue">
          <div
            v-if="scoped.row['checkResult']!=='未设置检查结果'&&scoped.row['checkResult']!=='停机或维护'"
          >{{ scoped.row.judgeResult||'' }}</div>
          <div v-if="scoped.row['checkResult']==='未设置检查结果'">{{ '未检' }}</div>
          <div v-if="scoped.row['checkResult']==='停机或维护'">{{ '停机' }}</div>
          <div v-else>{{ '' }}</div>
        </template>
        <template slot="operate" v-if="scoped.row.taskCode" slot-scope="scoped">
          <span class="table-btns-box" @click="edit(scoped.row)">
            <i class="el-icon-edit-outline"></i>
            <span>修改</span>
          </span>

          <span class="table-btns-box" @click="completeInfo(scoped.row)">
            <i class="el-icon-edit-outline"></i>
            <span>查看详情</span>
          </span>
        </template>
      </e-table>
      <AddEditDialog
        ref="addEditDialog"
        :edit-object="editObject"
        :show.sync="showAddEditDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
      <CompleteInfoDialog
        ref="CompleteInfoDialog"
        :edit-object="editObject"
        :show.sync="showCompleteInfoDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import inspectionDayReportApi from "@/api/equip-inspection/inspection-day-report";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import { mymixin } from "@/utils/mixin";
import SelectButton from "@/components/equipTypeSelectButton/selcetButton.vue";
import AddEditDialog from "./components/edit-result-dialog.vue";
import CompleteInfoDialog from "./components/complete-info-dialog.vue";
import { getToken } from "@/utils/auth";

export default {
  name: "InspectionDayReport",
  components: {
    BaseMainSlot,
    SelectButton,
    AddEditDialog,
    CompleteInfoDialog,
  },
  mixins: [mymixin],
  data() {
    return {
      // 所搜条件：点检任务名称
      taskName: "",
      // 所搜条件：点检设备
      equipmentName: "",
      // 所搜条件：选择时间
      startTime: "",
      endTime: "",
      tableData: [],
      generationTime: "",
      topitemtypeId: "任务",
      anCurrentPage: 1,
      anPageSize: 10,
      // 控制添加/编辑弹出框显示隐藏
      showAddEditDialog: false,
      //控制日报详情弹出框显示隐藏
      showCompleteInfoDialog: false,
      topitemSelectList: [
        { id: "任务", name: "任务" },
        { id: "异常任务", name: "异常任务" },
      ],
      tableLabel: [
        {
          label: "设备名称",
          param: "equipmentName",
          show: true,
          notSearch: true,
        },
        {
          label: "点检任务",
          param: "taskName",
          show: true,
          notSearch: true,
        },
        {
          label: "检查内容",
          param: "checkItemContent",
          show: true,
          notSearch: true,
        },
        {
          label: "标准值",
          param: "standardValue",
          show: true,
          slotName: "standardValue",
          notSearch: true,
        },
        {
          label: "检查结果",
          param: "checkResult",
          show: true,
          notSearch: true,
        },
        {
          label: "检查方式",
          param: "accessMethod",
          show: true,
          notSearch: true,
        },
        {
          label: "执行人",
          param: "staffName",
          show: true,
          notSearch: true,
        },
        {
          label: "生成时间",
          param: "generationTime",
          show: true,
          notSearch: true,
        },
        {
          label: "完成状态",
          param: "checkResult",
          slotName: "checkResult",
          show: true,
          notSearch: true,
        },
      ],
      // 表单事件
      tableOption: {
        label: "操作",
        options: [
          {
            label: "操作",
            slotName: "operate",
          },
        ],
      },
    };
  },
  watch: {},
  created() {
    var time = new Date();
    this.generationTime = this.$moment(time).format("YYYY/MM/DD");
    this.startTime = this.$moment().startOf("day").format("YYYY/MM/DD");
    this.endTime = this.$moment().format("YYYY/MM/DD");
  },
  mounted() {},
  methods: {
    //点击查看详情
    completeInfo(row) {
      console.log(row);
      this.editObject = JSON.parse(JSON.stringify(row));
      this.showCompleteInfoDialog = true;
    },
    // 获取点击的分页index
    topitemtype(e) {
      this.topitemtypeId = e;
      //默认展示所有异常任务数据
      // if (this.topitemtypeId === '异常任务') {
      //   this.startTime = null
      //   this.endTime = null
      // }
      // 获取表格数据
      this.queryPageList();
    },
    queryPageList() {
      if (this.topitemtypeId === "任务") {
        this.queryList();
      }
      if (this.topitemtypeId === "异常任务") {
        this.queryAnList();
      }
    },
    queryList() {
      this.loading = false;
      if (this.generationTime) {
        var params = {
          page: this.currentPage,
          size: this.pageSize,
          startTime: this.generationTime + " 00:00:00",
          endTime: this.generationTime + " 23:59:59",
        };
      } else {
        var params = {
          page: this.currentPage,
          size: this.pageSize,
        };
      }
      var condition = [
        {
          paramName: "orgainzationMark",
          value: getToken("organizationNo"),
          sign: "equals",
        },
      ];
      if (this.equipmentName) {
        condition.push({
          paramName: "equipmentName",
          value: this.equipmentName,
          sign: "like",
        });
      }
      if (this.taskName) {
        condition.push({
          paramName: "taskName",
          value: this.taskName,
          sign: "like",
        });
      }
      if (condition.length > 0) {
        params["condition"] = encodeURIComponent(JSON.stringify(condition));
      }
      inspectionDayReportApi.queryPageDailyList(params).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          this.totalSize = data.total;
          this.tableData = data.list;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    queryAnList() {
      this.loading = false;
      // if (this.dateRange.length > 0) {
      var params = {};
      var condition = [
        { paramName: "judgeResult", value: "异常", sign: "equals" },
        {
          paramName: "checkResult",
          value: "未设置检查结果",
          sign: "notEquals",
        },
        { paramName: "checkResult", value: "停机或维护", sign: "notEquals" },
        {
          paramName: "orgainzationMark",
          value: getToken("organizationNo"),
          sign: "equals",
        },
      ];
      if (this.equipmentName) {
        condition.push({
          paramName: "equipmentName",
          value: this.equipmentName,
          sign: "like",
        });
      }
      if (this.taskName) {
        condition.push({
          paramName: "taskName",
          value: this.taskName,
          sign: "like",
        });
      }
      if (this.startTime || this.endTime) {
        params = {
          page: this.anCurrentPage,
          size: this.anPageSize,
          startTime: this.startTime + " 00:00:00",
          endTime: this.endTime + " 23:59:59",
          condition: encodeURIComponent(JSON.stringify(condition)),
        };
      } else {
        params = {
          page: this.anCurrentPage,
          size: this.anPageSize,
          condition: encodeURIComponent(JSON.stringify(condition)),
        };
      }
      inspectionDayReportApi.queryPageDailyList(params).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          this.totalSize = data.total;
          this.tableData = data.list;
          this.addblankmet();
          this.resetActionBar();
        }
      });
      // } else {
      //   this.$message.error("请选择日报查询时间！");
      // }
    },
    changePageSize(pageSize) {
      if (this.topitemtypeId === "任务") {
        this.pageSize = pageSize;
      }
      if (this.topitemtypeId === "异常任务") {
        this.anPageSize = pageSize;
      }
      this.queryPageList();
    },
    changeCurrentPage(currentPage) {
      if (this.topitemtypeId === "任务") {
        this.currentPage = currentPage;
      }
      if (this.topitemtypeId === "异常任务") {
        this.anCurrentPage = currentPage;
      }
      this.queryPageList();
    },
    // 修改
    edit(row) {
      if (row.taskCode) {
        this.showAddEditDialog = true;
        this.editObject = JSON.parse(JSON.stringify(row));
      }
    },
    cancel() {
      this.showAddEditDialog = false;
      this.showCompleteInfoDialog = false;
      this.nowChanceStau = "";
      this.titleText = "";
      this.editObject = {};
      this.addActive = true;
      this.delActive = false;
      this.editActive = false;
      this.$refs.tableData.setCurrentRow();
      this.$refs.tableData.clearSelection();
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-collapse-item__header {
  height: 0px;
}
::v-deep .el-collapse-item__content {
  padding-bottom: 10px;
}
</style>
